﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XMLGener.Utils
{
    /// <summary>
    /// This class is used as message container used in
    /// loggin process. 
    /// </summary>
    public class XLogMessage
    {
        /// <summary>
        /// Construcotr of log-message instance.
        /// </summary>
        /// <param name="source">Sender of this message</param>
        /// <param name="message">Message content</param>
        /// <param name="type">Message character (message type)</param>
        public XLogMessage(string source,string message,LogType type)
        {
            this.source = source;
            this.message = message;
            this.type = type;
        }
 
        /// <summary>
        /// This enumeration is used for defining message character (type)
        /// </summary>
        public enum LogType { 
            /// <summary>
            /// Message of this type has detail information character
            /// </summary>
            VERBOSE,
            /// <summary>
            /// Message of this type has informational character
            /// </summary>
            LOG,
            /// <summary>
            /// Message of this type has warn character, 
            /// which should be displayed to user immediately, but it is not
            /// error
            /// </summary>
            WARNING,
            /// <summary>
            /// Message of this type is error message, which is shown 
            /// to user immediately.
            /// </summary>
            ERROR,
            /// <summary>
            /// Message of this type is error message, which is shown 
            /// to user immediately.
            /// </summary>
            ERROR_HINT};

        /// <summary>
        /// Log type
        /// </summary>
        public LogType type;

        /// <summary>
        /// Log content(message)
        /// </summary>
        public string message;

        /// <summary>
        /// Source target of message (who generates this message)
        /// Main use is in error logging.
        /// </summary>
        public string source;

        /// <summary>
        /// Method returns content of message.
        /// </summary>
        /// <returns>Formated content which contains type information (warning/error)</returns>
        public override string ToString()
        {
            if (this.type == LogType.ERROR)
                return String.Format("ERROR:[Source:{0}] {1}", source, message);
            if (this.type == LogType.ERROR_HINT)
                return String.Format("HINT:[Source:{0}] {1}", source, message);
            if (this.type == LogType.WARNING)
                return String.Format("WARNING:[Source:{0}] {1}", source, message);
            return String.Format("[Source:{0}] {1}", source, message);
        }

    }
}
